<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户信息管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
    <script>
        $(function () {
            let cks = $(".cks")
            //全选
            $("#ck").click(function () {
                for(let i = 0;i < cks.length;i++){
                    cks[i].checked = this.checked;
                }
           })
            //获取选中复选框的value值
            $("#dels").click(function () {
                let arr = new Array();
                for(let i = 0;i < cks.length;i++){
                  if (cks[i].checked){
                      arr.push(cks[i].value);
                  }
                }
               location.href="${pageContext.request.contextPath}/user?method=delete&uid="+arr;
            })

        });

    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">用户信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th><input type="checkbox" id="ck">全选</th>
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>籍贯</th>
            <th>QQ</th>
            <th>邮箱</th>
            <th>操作</th>
        </tr>

        <c:forEach items="${pageInfo.list}" var="user" varStatus="s">
            <tr>
                <td><input type="checkbox" class="cks" value="${user.id}"></td>
                <td>${s.count}</td>
                <td>${user.name}</td>
                <td>${user.genderStr}</td>
                <td>${user.age}</td>
                <td>${user.address}</td>
                <td>${user.qq}</td>
                <td>${user.email}</td>
                <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/user?method=findById&uid=${user.id}">修改</a>&nbsp;<a class="btn btn-default btn-sm"
                href="${pageContext.request.contextPath}/user?method=delete&uid=${user.id}" id="del">删除</a></td>
            </tr>
        </c:forEach>


        <tr>
            <td colspan="1" rowspan="2" align="center"><a class="btn btn-primary" href="javascript:void(0)" id="dels">批量删除</a></td>
            <td colspan="8" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/city">添加联系人</a></td>
        </tr>
        <tr>
            <td colspan="9" align="center">
                <a href="javascript:void(0)" class="btn btn-primary">总页数:&nbsp;&nbsp;&nbsp;&nbsp;${pageInfo.pages}</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="javascript:void(0)" class="btn btn-primary">总记录数:&nbsp;&nbsp;&nbsp;&nbsp;${pageInfo.total}</a>&nbsp;&nbsp;&nbsp;
               <%--上一页--%>
                <c:if test="${pageInfo.hasPreviousPage}">
                    <a class="btn btn-primary" href="${pageContext.request.contextPath}/user?method=findAll&pageNum=${pageInfo.prePage}">上一页</a>
                </c:if>
                
                <c:forEach  begin="1" end="${pageInfo.pages}" var="i">
                    <a href="${pageContext.request.contextPath}/user?method=findAll&pageNum=${i}" class="btn btn-primary">${i}</a>
                </c:forEach>
                
                <%--下一页--%>
               <c:if test="${pageInfo.hasNextPage}">
                   <a class="btn btn-primary" href="${pageContext.request.contextPath}/user?method=findAll&pageNum=${pageInfo.nextPage}">下一页</a>
               </c:if>

            </td>

        </tr>
    </table>
</div>
</body>
</html>
